package com.emm.yixun.mobile.ui.customer;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.emm.yixun.mobile.R;

import java.util.List;

/**
 * Created by tangxin on 2017/9/22.
 */

public class InvestigationAdapter extends BaseAdapter {

    List<queryProjectQuestionnaireList.appProjectQuestionnaireList> questionnaireList;

    public InvestigationAdapter(List<queryProjectQuestionnaireList.appProjectQuestionnaireList> questionnaireList) {
        this.questionnaireList = questionnaireList;
    }

    public void setInvestigationAdapter(List<queryProjectQuestionnaireList.appProjectQuestionnaireList> questionnaireList) {
        this.questionnaireList = questionnaireList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return null == questionnaireList ? 0 : questionnaireList.size();
    }

    @Override
    public Object getItem(int position) {
        return null == questionnaireList ? null : questionnaireList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ItemView itemView = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_investigation_item, null);
            itemView = new ItemView();
            itemView.tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
            convertView.setTag(itemView);
        } else {
            itemView = (ItemView) convertView.getTag();
        }
        itemView.tvTitle.setText(questionnaireList.get(position).getQuestionnaireName());
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemClick.item(questionnaireList.get(position));
            }
        });
        return convertView;
    }

    public static class ItemView {

        TextView tvTitle;

    }

    itemClick itemClick;

    public void setItemClick(itemClick itemClick) {
        this.itemClick = itemClick;
    }

    interface itemClick {
        void item(queryProjectQuestionnaireList.appProjectQuestionnaireList itemBean);
    }

}
